package com.atguigu.dao.impl;

import com.atguigu.dao.UpdateTomcatCodeTaskDao;
import com.atguigu.pojo.UpdateTomcatCodeTask;

import java.util.List;


public class UpdateTomcatCodeTaskDaoImpl extends BaseDao implements UpdateTomcatCodeTaskDao {

    @Override
    public int addUpdateTomcatCodeTask(UpdateTomcatCodeTask updateTomcatCodeTask) {
        System.out.println("UpdateTomcatCodeTaskDaoImpl程序在[" + Thread.currentThread().getName() + "]线程中");
        String sql = "insert into t_updateTomcatCodeTask(`id`,`name`,`file`,`projectType`,`projectModule`,`status`) values(?,?,?,?,?,?);";
        return update(sql,updateTomcatCodeTask.getId(), updateTomcatCodeTask.getName(),updateTomcatCodeTask.getFile(),updateTomcatCodeTask.getProjectType(),updateTomcatCodeTask.getProjectModule(),updateTomcatCodeTask.getStatus());
    }

    @Override
    public int deleteUpdateTomcatCodeTaskById(String id) {
        String sql = "delete from t_updateTomcatCodeTask where id=?";
        return update(sql, id);
    }

    @Override
    public int updateUpdateTomcatCodeTask(UpdateTomcatCodeTask updateTomcatCodeTask) {
        String sql = "update t_updateTomcatCodeTask set `name`=?,`file`=?,`projectType`=?,`projectModule`=?,`status`=? where id=?";
        return update(sql, updateTomcatCodeTask.getName(),updateTomcatCodeTask.getFile(),updateTomcatCodeTask.getProjectType(),updateTomcatCodeTask.getProjectModule(),updateTomcatCodeTask.getStatus(), updateTomcatCodeTask.getId());
    }

    @Override
    public UpdateTomcatCodeTask queryUpdateTomcatCodeTaskById(String id) {
        String sql = "select `id`,`name`,`file`,`projectType`,`projectModule`,`status` from t_updateTomcatCodeTask where id=?";
        return queryForOne(UpdateTomcatCodeTask.class, sql, id);
    }

    @Override
    public List<UpdateTomcatCodeTask> queryUpdateTomcatCodeTasks() {// 查询全部
        String sql = "select `id`,`name`,`file`,`projectType`,`projectModule`,`status` from t_updateTomcatCodeTask";
        return queryForList(UpdateTomcatCodeTask.class, sql);
    }

    @Override
    public Integer queryForPageTotalCount() {//查询总条目数,为page分片做准备
        String sql = "select count(*) from t_updateTomcatCodeTask";
        Number updateTomcatCodeTaskCount = (Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return updateTomcatCodeTaskCount.intValue();
    }

    @Override
    public List<UpdateTomcatCodeTask> queryForPageItems(Integer begin, Integer pageSize) {
        String sql = "select `id`,`name`,`file`,`projectType`,`projectModule`,`status` from t_updateTomcatCodeTask limit ?,?";
        return queryForList(UpdateTomcatCodeTask.class, sql, begin, pageSize);//查询数据片段
    }
}


